<template>
  <div class="infinite-list-wrapper" style="overflow: auto">
    <ul
      class="list"
      v-infinite-scroll="load"
      infinite-scroll-disabled="disabled"
    >
      <li
        v-for="(info, index) in infos.slice(0, 8)"
        :key="index"
        class="list-item"
        @click="hot(info)"
      >
        <router-link
          :to="{ name: 'storyDetail', params: { id: info.story_id } }"
        >
          <div class="item-heading">
            <h2 >
              {{ info.title }}
            </h2>
          </div>

          <div class="item-content">
            <p><img :src="info.newpic" /></p>
            <p v-html="info.s_content">{{ info.s_content }}</p>
          </div>
          <div class="item-hot">
            <span class="hot1">{{ info.reading }}</span>
            <span class="hot2">热度</span>
          </div>
        </router-link>
      </li>
    </ul>
    <p v-if="loading">加载中...</p>
    <p v-if="noMore">没有更多了</p>
  </div>
</template>

<script>
import { Bus } from "../main.js";
export default {
  data() {
    return {
      infos: [],
      count: 0,
      loading: false,
      categroy: "",
      hoted:''
    };
  },
  computed: {
    noMore() {
      return this.count >= 5;
    },
    disabled() {
      return this.loading || this.noMore;
    },
  },
  methods: {
    hot(info){
    this.hoted = ++info.reading;
    this.$axios
        .get("/addreading.do?story_id=" + info.story_id
        +"&reading="+this.hoted)
        .then((response) => {
          this.up = response.data;
        if(this.up>0){
          this.$axios
        .get("/search.do?search=" + this.search)
        .then((response) => {
          this.infos = response.data;
          console.log(this.infos);
        })
        }
        })
    },
    load() {
      this.loading = true;
      setTimeout(() => {
        this.count += 2;
        this.loading = false;
      }, 1000);
    },
  },
  mounted() {
 
      this.$axios
        .get("/allStory.do")
        .then((response) => {
          this.infos = response.data;
          console.log(this.infos);
        })
        .catch(function (error) {
          console.log(error);
        });

    Bus.$on("moreCategroy", (val) => {
      this.categroy = val;
      console.log(this.categroy + "123");
 
      if(this.categroy!= null){
        this.$axios
          .get("/getStoryByType.do?type="+this.categroy)
          .then((response) => {
            this.infos = response.data;
            console.log(this.infos);
          })
          .catch(function (error) {
            console.log(error);
          });
      }
   });
   
  },
};
</script>

<style scoped="scoped">
a {
  text-decoration: none;
}
.infinite-list-wrapper {
  width: 110%;
}
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  margin-left: 10%;
  margin-top: 5%;
}
.list-item {
  border-bottom: 1px solid #d3cfcf;
  margin-bottom: 10px;
  padding-bottom: 10px;
}
.item-heading {
  text-align: left;
}
h2 {
  color: rgb(32, 31, 31);
}
.item-content {
  text-align: left;
  color: rgb(32, 31, 31);
  font-size: 15px;
  display: flex;
}
.item-content p:nth-child(1) {
  width: 20%;
}
.item-content p:nth-child(2) {
  width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  line-height: 2.5;
  margin-left: 20px;
}
.item-content p img {
  width: 180px;
  border-radius: 5%;
  max-height: 150px;
}
.item-hot {
  text-align: left;
  margin-top: 10px;
  font-size: 15px;
}
.hot1 {
  color: red;
}
.hot2 {
  color: rgb(32, 31, 31);
}
</style>